<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>建立一个新的 FTP 连接</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.ftp-close.html">« ftp_close</a></li>
      <li style="float: right;"><a href="function.ftp-delete.html">ftp_delete »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.ftp.html">FTP 函数</a></li>
    <li>建立一个新的 FTP 连接</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.ftp-connect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ftp_connect</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ftp_connect</span> &mdash; <span class="dc-title">建立一个新的 FTP 连接</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.ftp-connect-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ftp_connect</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$host</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$port</code><span class="initializer"> = 21</span></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$timeout</code><span class="initializer"> = 90</span></span>): <span class="type">resource</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>ftp_connect()</strong></span> 将会建立一个 FTP 连接到指定的服务器 <code class="parameter">host</code>。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.ftp-connect-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">host</code></dt>

     <dd>

      <p class="para">
       要连接的服务器地址。此参数后面不应以斜线结尾，前面也不需要用 <code class="literal">ftp://</code> 开头。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">port</code></dt>

     <dd>

      <p class="para">
        为要连接到的 FTP 器的端口号，如果没有设置或者为 0，则会使用默认的端口 21 来连接。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">timeout</code></dt>

     <dd>

      <p class="para">
        用来设置网络传输的超时时间限制。如果此选项留空，则默认的值为 90 秒。超时时间可以在任何时候通过函数
        <span class="function"><a href="function.ftp-set-option.html" class="function">ftp_set_option()</a></span> 及 <span class="function"><a href="function.ftp-get-option.html" class="function">ftp_get_option()</a></span> 来改变和获取。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.ftp-connect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    如果成功返回一个 FTP 连接资源句柄，发生错误则返回 <strong><code>false</code></strong>。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.ftp-connect-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4266">
    <p><strong>示例 #1 <span class="function"><strong>ftp_connect()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$ftp_server&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"ftp.example.com"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;set&nbsp;up&nbsp;a&nbsp;connection&nbsp;or&nbsp;die<br /></span><span style="color: #0000BB">$conn_id&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ftp_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$ftp_server</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Couldn't&nbsp;connect&nbsp;to&nbsp;</span><span style="color: #0000BB">$ftp_server</span><span style="color: #DD0000">"</span><span style="color: #007700">);&nbsp;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>  
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.ftp-connect-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.ftp-close.html" class="function" rel="rdfs-seeAlso">ftp_close()</a> - 关闭一个 FTP 连接</span></li>
    <li class="member"><span class="function"><a href="function.ftp-ssl-connect.html" class="function" rel="rdfs-seeAlso">ftp_ssl_connect()</a> - 打开 SSL-FTP 连接</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>